import { Message } from '@arco-design/web-vue'
import { saveSystemMenu } from '@/apis'
import { FormRef, emit } from './AddMenuModal.vue'

export const save = async () => {
  try {
    const info = await FormRef.value?.validate()
    if (info) return false
    const meta = JSON.stringify({
      hidden: form.hidden,
      affix: form.affix,
      breadcrumb: form.breadcrumb,
      showInTabs: form.showInTabs,
      activeMenu: form.activeMenu,
      alwaysShow: form.alwaysShow
    })
    form.meta = meta
    const res = await saveSystemMenu(form)
    if (res.data) {
      Message.success('模拟保存成功')
      emit('save-success')
      return true
    } else {
      return false
    }
  } catch (error) {
    return false
  }
}
